package servlets;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dbmanager.MSSQL;
import dbmanager.SQLManager;
import domain.KLIENT;

/**
 * Servlet implementation class KlientPomocnyServlet
 */
@WebServlet("/KlientPomocnyServlet")
public class KlientPomocnyServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public KlientPomocnyServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("UTF-8");
		
		String idk = request.getParameter("idk");
		String meno = request.getParameter("meno");
		String priezvisko = request.getParameter("priezvisko");
		String rodc = request.getParameter("rod_cislo");
		String adresa = request.getParameter("adresa");
		String email = request.getParameter("email");
		String telc = request.getParameter("tel_cislo");
		String dat_zac = request.getParameter("dat_zac");
		String pobocka = request.getParameter("idp");
				
		KLIENT k = new KLIENT(Integer.decode(idk),Integer.decode(pobocka),meno, priezvisko, rodc, adresa, telc, email,dat_zac, null);
		
		MSSQL ms = new MSSQL("127.0.0.1");
		SQLManager s = ms.connect();
		s.insertN(k,"BA");
		ms.disconnect(s.getConnection());
		
		request.setAttribute("k", k);
		request.getRequestDispatcher("NovyUcet2.jsp").forward(request, response);
	}

}
